package org.example;

import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class WeChatAutomationSender {

    //模拟机器人发送消息
    public static void main(String[] args) {
        try {
            // 给程序 5 秒切换到微信聊天窗口
            System.out.println("请切换到微信聊天窗口，程序将在 5 秒后开始...");
            Thread.sleep(5000);

            // 待发送的消息
            String message = "Hello,你好！这是自动消息。";

            // 将消息放入剪贴板
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(message), null);

            // 初始化 Robot
            Robot robot = new Robot();

           for (int i = 0; i < 10; i++){
               // 模拟 Ctrl + V 粘贴消息
               robot.keyPress(KeyEvent.VK_CONTROL);
               robot.keyPress(KeyEvent.VK_V);
               robot.keyRelease(KeyEvent.VK_V);
               robot.keyRelease(KeyEvent.VK_CONTROL);

               // 模拟回车键发送消息
               robot.keyPress(KeyEvent.VK_ENTER);
               robot.keyRelease(KeyEvent.VK_ENTER);
           }

            System.out.println("消息发送成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

